package se.webbzon.oschi01.world;

import se.webbzon.oschi01.utils.Progress;
import se.webbzon.oschi01.utils.Writer;

public abstract class WorldWriter<D> implements Writer<World,D> {

	public abstract Progress<Object> getProgress();
	
	public static <D> Progress<Object> write(final WorldWriter<D> writer, final World world, final D destination) {
		
		final Progress<Object> progress = writer.getProgress();
		
		Thread thread = new Thread() {
			
			@Override public void run() {
				try {
					writer.write(world, destination);
				} catch (Throwable e) {
					progress.abort(new Exception(e));
				}
			}
			
		};
		
		thread.start();
		return progress;
	}
	
}
